home *** CD-ROM | disk | FTP | other *** search
/ Web Page Construction Kit 3.0 / Web Page Construction Kit 3.0.iso / pc / source / 3rdparty / java / jdesnpro / data.1 / JDPLayout5.java < prev    next >
Encoding:
Text File  |  1996-08-04  |  14.1 KB  |  484 lines

  1. >XXX0486  Total lines for the build status message calculation
  2. //--------------------------------------------------------------------
  3. //                                                                    
  4. >001//  Module:       <JDPModule>                                       
  5. >002//  Description:  <Class Description>
  6. //                                                                    
  7. //--------------------------------------------------------------------
  8.  
  9. import java.awt.*;
  10. import java.applet.*;
  11. import java.util.StringTokenizer;
  12. import java.util.Vector;
  13.  
  14.  
  15. >003public class <JDPUserBill> extends JDPClassLayout {
  16.  
  17.     JDPUser user;
  18.     JDPJagg jaggSQL;
  19.     JDPWhereClause jdpWhereClause;
  20.     JDPSearchResults searchResults;
  21.     JDPChart chartPanel;
  22.     JDPChartParms p;
  23.  
  24.     Choice thisChartType;
  25.     Choice thisAutoScale;
  26.     Choice thisAutoZoom;
  27.  
  28.     String[] psortChoice;
  29.     String[] pdisplayChoice;
  30.     int itemIndex;
  31.     boolean insertRequested = false;
  32.     boolean deleteRequested = false;
  33.     String pfromWhereClause;
  34.     String prevSQL = "";
  35.     Color[] colorList = {Color.blue,Color.cyan,Color.green,Color.magenta,Color.orange,
  36.                          Color.red,Color.white,Color.yellow,Color.pink,Color.black,
  37.                          Color.darkGray,Color.gray};
  38.  
  39.     public void InitClass(JDPUser user, Panel targetPanel, String moduleParameter) {
  40.  
  41.         this.user = user;
  42.         //
  43.         //  Set JAGG settings for this class
  44.         //
  45.         jaggSQL = new JDPJagg(user.jaggPath);
  46.         jaggSQL.setNULL("space");
  47. >994        jaggSQL.setMRW("<maxRows>");
  48. >998        jaggSQL.setDSN("<datasource>");
  49. >999        jaggSQL.setCSTR("<connectstr>");
  50.  
  51.         setLayout(new BorderLayout());
  52.         setFont(user.plainFont);
  53.  
  54.         Panel mainPanel = new Panel();
  55.         mainPanel.setLayout(new BorderLayout());
  56.         Panel chartMainPanel = new Panel();
  57.         chartMainPanel.setLayout(new BorderLayout());
  58.         Panel centerPanel = new Panel();
  59.         centerPanel.setLayout(new BorderLayout());
  60.         Panel centerMainPanel = new Panel();
  61.         centerMainPanel.setLayout(new BorderLayout());
  62.         Panel centerTopPanel = new JDPScrollPanel();
  63.         Panel leftPanel = new Panel();
  64.         leftPanel.setLayout(new BorderLayout());
  65.         
  66.         p = new JDPChartParms();
  67. >140        p.chartType = <>;
  68.         thisChartType = new Choice();
  69.         thisChartType.addItem("Column");
  70.         thisChartType.addItem("Bar");
  71.         thisChartType.addItem("Line");
  72.         thisChartType.addItem("Area");
  73.         thisChartType.addItem("Pie");
  74.         thisChartType.select(p.chartType-1);
  75.  
  76. >154        p.autoscale = <>;
  77.         thisAutoScale = new Choice();
  78.         thisAutoScale.addItem("Yes");
  79.         thisAutoScale.addItem("No");
  80.         if (!p.autoscale) thisAutoScale.select("No");
  81. >155        p.autozoom = <>;
  82.          thisAutoZoom = new Choice();
  83.         thisAutoZoom.addItem("Yes");
  84.         thisAutoZoom.addItem("No");
  85.         if (!p.autozoom) thisAutoZoom.select("No");
  86.  
  87.         chartPanel = new JDPChart(user,p);
  88.         chartMainPanel.add("Center",chartPanel);
  89.         mainPanel.add("Center",chartMainPanel);
  90.  
  91.         Panel controlPanel = new Panel();
  92.         controlPanel.setLayout(new JDPLineLayout(1));
  93.         chartMainPanel.add("South",controlPanel);
  94.         controlPanel.add("Left",new JDPWrapLabel(user,"Type:"));
  95.         controlPanel.add("Left",thisChartType);
  96.         controlPanel.add("Left",new JDPWrapLabel(user,"Auto Scale:"));
  97.         controlPanel.add("Left",thisAutoScale);
  98.         controlPanel.add("Left",new JDPWrapLabel(user,"Auto Zoom:"));
  99.         controlPanel.add("Left",thisAutoZoom);
  100.  
  101.         //
  102.         //  Define parameters for JDPSearchResults
  103.         //
  104. >005        String pselectFields = "<>"; String[] psdisplayFields = {<>};
  105. >006        pfromWhereClause = "<FROM JDPUser WHERE >";
  106.  
  107. >007        psortChoice = new String[<5>];
  108. >008        psortChoice[<0>] = "<username>";
  109.  
  110. >009        String[] psortChoiceText = {<"Sort by User Name","Sort by Card Number">};
  111.         pdisplayChoice = psortChoice;
  112.  
  113. >010        boolean pdisplayCount = <true>;
  114. >011        String pcountText = "<Total Entries:>";
  115.     
  116.         //
  117.         //  Define parameters for JDPWhereClause
  118.         //
  119. >016        String[] pchooseFrom = new String[<7>];
  120. >017        pchooseFrom[<0>] = "<Account Name>";
  121.  
  122. >018        String[] pactualchooseFrom = new String[<7>];
  123. >019        pactualchooseFrom[<0>] = "<username>";
  124.  
  125. >020        String[][] pmatchUsing = new String[<7>][<7>];
  126. >021        pmatchUsing[<0>][<0>] = "<Begins with>";
  127.  
  128. >022        String[][] pactualmatchUsing = new String[<7>][<7>];
  129. >023        pactualmatchUsing[<0>][<0>] = "< like >";
  130.  
  131. >024        boolean[] constantIsString = new boolean[<7>];
  132. >025        constantIsString[<0>] = <true>;
  133.  
  134. >026        int[] constantLength = new int[<7>];
  135. >027        constantLength[<0>] = <20>;
  136.  
  137.         //
  138.         //  Add JDPWhereClause search panel
  139.         //
  140.         if (pchooseFrom.length > 0) {
  141. >028            jdpWhereClause = new JDPWhereClause(user, "<UserBill>", true, "<pinitChoice>", pchooseFrom, pactualchooseFrom,
  142.                                                 pmatchUsing, pactualmatchUsing, null, null,
  143.                                                 constantLength, constantIsString);
  144.             leftPanel.add("North",jdpWhereClause);
  145.         }
  146.         //
  147.         //  Add JDPSearchResults result list
  148.         //
  149.         if (psortChoice.length > 0) {
  150. >029            searchResults = new JDPSearchResults(user, <false>, jaggSQL, <false>, pselectFields, psdisplayFields, pfromWhereClause, psortChoiceText, psortChoice, pdisplayChoice, "<pinitChoice>", pdisplayCount, pcountText);
  151.             leftPanel.add("Center",searchResults);
  152.             mainPanel.add("West",leftPanel);
  153.         }
  154.  
  155. >030        add("Center",new JDPChiselFramePanel(user,"<User Billing Details>",mainPanel,"North"));
  156.         if (psortChoice.length > 0) {
  157.             newSearch();
  158.         }
  159.         // repaint the panel
  160.         targetPanel.add("Center",this);
  161.         targetPanel.paintAll(targetPanel.getGraphics());
  162.         //
  163.         //  Add the handle to this panel to the global vector so other panels can
  164.         //  access this one
  165.         //
  166.         user.gParm.addElement(this);
  167.     }
  168.  
  169.     //
  170.     //  Handle screen events
  171.     //
  172.     public boolean handleEvent(Event e) {
  173.  
  174.         switch (e.id) {
  175.         case Event.ACTION_EVENT:
  176.             if (e.target instanceof List) {
  177.                 if (e.target.equals(searchResults.resultList)) {
  178.                     loadChart();
  179.                     chartPanel.calculateScaling();
  180.                     chartPanel.repaint();
  181.                     return true;
  182.                 }
  183.             }
  184.             if (e.target instanceof JDPTreePicker) {
  185.                 if (e.target.equals(searchResults.tree)) {
  186.                     loadChart();
  187.                     chartPanel.calculateScaling();
  188.                     chartPanel.repaint();
  189.                     return true;
  190.                 }
  191.             }
  192.             if (e.target instanceof Button) {
  193.                 String choice = (String)e.arg;
  194.                 if (choice.trim().compareTo("Search") == 0) {
  195.                     insertRequested = false;
  196.                     deleteRequested = false;
  197.                     newSearch();
  198.                     return true;
  199.                 }
  200.                 return true;
  201.             }
  202.             if (e.target instanceof Choice) {
  203.                 if ((e.target.equals(thisChartType)) ||
  204.                     (e.target.equals(thisAutoScale)) ||
  205.                     (e.target.equals(thisAutoZoom))) {
  206.                     loadChart();
  207.                     chartPanel.calculateScaling();
  208.                     chartPanel.repaint();
  209.                     return true;
  210.                 }
  211.                 return true;
  212.             }
  213.             if (e.target instanceof TextField) {
  214.                 if ((jdpWhereClause != null) && (e.target.equals(jdpWhereClause.matchConstant))) {
  215.                     insertRequested = false;
  216.                     deleteRequested = false;
  217.                     newSearch();
  218.                     return true;
  219.                 }
  220.                 checkFields();
  221.                 return true;
  222.             }
  223.             return false;
  224.  
  225.         case Event.KEY_PRESS:
  226.             if (e.key == '\t') {
  227.                 //  handle tabbing between components
  228.                 if (e.modifiers != Event.SHIFT_MASK) {
  229.                 } else {
  230.                 }
  231.                 return true;
  232.             }
  233.             return false;
  234.  
  235.         case Event.WINDOW_EXPOSE:
  236.             if (e.target instanceof JDPTabSelectTopPanel) {
  237.                 //
  238.                 //  This is where you place code to get executed when this panel is
  239.                 //  reactivated from the tab menu
  240.                 //
  241.                 return true;
  242.             }
  243.             return false;
  244.  
  245.         default:
  246.             return false;
  247.  
  248.         }
  249.     }
  250.  
  251.     //
  252.     //  Retrieve the handle to another panel so as to be able to interact with it
  253.     //
  254.     public void retrieveHandle() {
  255.  
  256.         for (int ix=0; ix<user.gParm.size(); ix++) {
  257.             //
  258.             //  Activate the next four lines of code to retrieve the handle to another 
  259.             //  Panel within your JDP system. Of course you should declare the variable 
  260.             //  at the top of this source instead of within this method so you can 
  261.             //  access it from all the methods within this class. You only need to 
  262.             //  substitute DemoClass with the name ouf your class. You should call this 
  263.             //  method from somewhere else in this class. To access a variable from 
  264.             //  your resulting class use:
  265.             //     if (DemoClassHandle != null) mynewvar = demoClassHandle.variable;
  266.             //
  267. //            if (user.gParm.elementAt(ix) instanceof DemoClass19) {
  268. //                DemoClass19 DemoClassHandle = (DemoClass19)user.gParm.elementAt(ix);
  269. //                return;
  270. //            }
  271.         }
  272.     }
  273.  
  274.     //
  275.     //  The search button was pressed so rerun the query with the new search criteria
  276.     //
  277.     public void newSearch() {
  278.  
  279.         String whereClause;
  280.  
  281.         whereClause = pfromWhereClause;
  282.         if (jdpWhereClause != null) {
  283.             whereClause = whereClause + " AND " + jdpWhereClause.whereClause;
  284.         }
  285.         searchResults.setFromWhereClause(whereClause);
  286.         searchResults.clearList();
  287.         searchResults.loadList();
  288.     }
  289.  
  290.     //
  291.     //  Load the selected item
  292.     //
  293.     public void loadData() {
  294.  
  295.         StringTokenizer stok;
  296.         int recCount = 0;
  297.         Vector results = new Vector();
  298.         String sep = user.jaggSQL.getSEP();
  299.         int actualRows = 0;
  300.         String row;
  301.         String whereClause = "(1=1)";
  302.  
  303.         if ((itemIndex = searchResults.getSelectedIndex()) < 0) {
  304.             clearFields();
  305.             return;
  306.         }
  307.         
  308.         if (jdpWhereClause != null) whereClause = jdpWhereClause.whereClause;
  309.  
  310. >130        int groupCount = <>;
  311. >131        int seriesCount = <>;
  312.  
  313. >132        String SQL = "<SELECT >";
  314.  
  315.  
  316.         prevSQL = SQL;
  317.         user.mainmsg.setStatusMsg("Accessing database...", 0);
  318.  
  319.         recCount = jaggSQL.execSQL(SQL, results);
  320.  
  321.         if(recCount == -1) {
  322.             user.mainmsg.setStatusMsg("SQL error. Contact the System Administrator", 20);
  323.             System.out.println("loadData SQL: " + SQL);
  324.             return;
  325.         }
  326.         //
  327.         //  Initialise result arrays
  328.         //
  329.         int columnCount = jaggSQL.getColumnCount();
  330.         actualRows = jaggSQL.getRowCount();
  331.  
  332.         if (seriesCount <= 0) {
  333.             p.chartData = new float[columnCount-groupCount][actualRows];
  334.             p.xaxisLabel = new String[actualRows];
  335.             p.piechartData = new float[actualRows];
  336.             p.pieSplitSegment = new boolean[actualRows];
  337.             p.pieLabel = new String[actualRows];
  338.             if (p.chartType == JDPChart.PIE) {
  339.                 p.elementColor = new Color[actualRows];
  340.                 p.elementBorderColor = new Color[actualRows];
  341.                  p.elementLegend = new String[actualRows];
  342.             }
  343.             for (int ix=0; ix<actualRows; ix++) {
  344.                 row = (String)results.elementAt(ix);
  345.                 stok = new StringTokenizer(row);
  346.                 p.xaxisLabel[ix] = "";
  347.                 if (groupCount > 0) p.xaxisLabel[ix] = stok.nextToken(sep).trim();
  348.                 for (int iz=0; iz<columnCount-groupCount; iz++) {
  349.                     p.chartData[iz][ix] = Float.valueOf(stok.nextToken(sep).trim()).floatValue();
  350.                 }
  351.                 p.pieLabel[ix] = p.xaxisLabel[ix];
  352.                 p.piechartData[ix] = p.chartData[0][ix];
  353.                 if (p.chartType == JDPChart.PIE) {
  354.                     p.elementColor[ix] = colorList[ix%12];
  355.                     p.elementBorderColor[ix] = Color.black;
  356.                      p.elementLegend[ix] = p.pieLabel[ix];
  357.                 }
  358.             }
  359.         } else {
  360.             float[][] tempchartData = new float[100][actualRows];
  361.             p.xaxisLabel = new String[actualRows];
  362.             Vector group = new Vector();
  363.             if (groupCount == 0) group.addElement("");
  364.             Vector series = new Vector();
  365.             for (int ix=0; ix<actualRows; ix++) {
  366.                 row = (String)results.elementAt(ix);
  367.                 stok = new StringTokenizer(row);
  368.                 p.xaxisLabel[ix] = "";
  369.                 int groupIndex = 0;
  370.                 if (groupCount > 0) {
  371.                     String groupValue = stok.nextToken(sep).trim();
  372.                     groupIndex = group.indexOf(groupValue);
  373.                     if (groupIndex < 0) {
  374.                         group.addElement(groupValue);
  375.                         groupIndex = group.indexOf(groupValue);
  376.                         p.xaxisLabel[groupIndex] = groupValue;
  377.                     }
  378.                 }
  379.                 String seriesValue = stok.nextToken(sep).trim();
  380.                 int seriesIndex = series.indexOf(seriesValue);
  381.                 if (seriesIndex < 0) {
  382.                     series.addElement(seriesValue);
  383.                     seriesIndex = series.indexOf(seriesValue);
  384.                 }
  385.                 tempchartData[seriesIndex][groupIndex] = Float.valueOf(stok.nextToken(sep).trim()).floatValue();
  386.             }
  387.  
  388.             int numbars = series.size();
  389.             p.chartData = new float[numbars][group.size()];
  390.             for (int ix=0; ix<numbars; ix++) {
  391.                 for (int iy=0; iy<group.size(); iy++) {
  392.                     p.chartData[ix][iy] = tempchartData[ix][iy];
  393.                 }
  394.             }
  395.             p.elementColor = new Color[numbars];
  396.             p.elementBorderColor = new Color[numbars];
  397.              p.elementLegend = new String[numbars];
  398.             for (int ix=0; ix<numbars; ix++) {
  399.                 p.elementColor[ix] = colorList[ix%12];
  400.                 p.elementBorderColor[ix] = Color.black;
  401.                  p.elementLegend[ix] = (String)series.elementAt(ix);
  402.             }
  403.         }
  404.         user.mainmsg.clearStatusMsg();
  405.     }
  406.  
  407.  
  408.     //
  409.     //  Clear the screen fields for a new option
  410.     //
  411.     public void clearFields() {
  412.  
  413.     }
  414.  
  415.     //
  416.     //  Load all of the Screen Choices
  417.     //
  418.     public void loadChoices() {
  419.  
  420.     }
  421.  
  422.     //
  423.     //  Perform component validations
  424.     //
  425.     public boolean checkFields() {
  426.  
  427.         return true;
  428.  
  429.     }
  430.  
  431.     //
  432.     //  Load the parameters for the selected chart
  433.     //
  434.     public void loadChart() {
  435.  
  436.         p.chartType = thisChartType.getSelectedIndex()+1;
  437.         p.autoscale = thisAutoScale.getSelectedItem().equals("Yes");
  438.         p.autozoom = thisAutoZoom.getSelectedItem().equals("Yes");
  439.  
  440. >141        p.chartTitle = "<>";
  441.         p.chartTitleFont = user.boldFont.getName();
  442. >142        p.chartTitleColor = user.u._cvtcolor("<>");
  443.  
  444. >143        p.xaxisTitle = "<>";
  445.         p.xaxisTitleFont = user.boldFont.getName();
  446. >144        p.xaxisTitleColor = user.u._cvtcolor("<>");
  447.  
  448.         p.yaxisLabel = new String[10];
  449.  
  450.         p.elementLegendFont = user.boldFont.getName();
  451.  
  452. >145        p.xaxisLabelColor = user.u._cvtcolor("<>");
  453. >146        p.yaxisLabelColor = user.u._cvtcolor("<>");
  454. >147        p.chartFrameColor = user.u._cvtcolor("<>");
  455.  
  456. >148        p.elementLegend = new String[<>];
  457. >148        p.elementColor = new Color[<>];
  458. >148        p.elementBorderColor = new Color[<>];
  459. >149        p.elementLegend[<iy>] = "<selectChartDef.elementLegend[ix]>";
  460. >150        p.elementColor[<iy>] = user.u._cvtcolor("<>");
  461. >151        p.elementBorderColor[<iy>] = user.u._cvtcolor("<selectChartDef.elementBorderColor[ix]>");
  462.  
  463. >152        p.gridLineSetting = <JDPChart.HORIZONTAL + JDPChart.VERTICAL + JDPChart.FOREGROUND + JDPChart.BACKGROUND>;
  464. >153        p.gridColor = user.u._cvtcolor("<>");
  465.  
  466. >156        p.maxPlotValue = <>;
  467. >157        p.minPlotValue = <>;
  468.  
  469.         if ((p.chartType == JDPChart.COLUMN) || (p.chartType == JDPChart.BAR) ||
  470.             (p.chartType == JDPChart.AREA)) {
  471.             p.autozoom = false;
  472.         }
  473.  
  474.         p.pieLabel = p.elementLegend;
  475.         p.pieLabelColor = p.xaxisTitleColor;
  476.  
  477.         loadData();
  478.  
  479.  
  480.     }
  481.  
  482.  
  483. }
  484.